<template>
  <div id="app">
    <el-row class="tac">
    <el-col :span="3">
      <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        @open="handleOpen"
        @close="handleClose"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
        <el-row :span="6">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-download"></i>
              <span>数据处理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="1-1" @click="ExportUser">导出用户Excel</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item index="1-2" @click="ExportLog">导出数据Excel</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-row>
        <el-row :span="6">
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span>事务处理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="2-1" @click="ToComplaints">投诉事务</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item index="2-2" @click="ToReports">举报事务</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item index="2-3" @click="ToDebates">申诉事务</el-menu-item>
            </el-menu-item-group>
<!--            <el-submenu index="2-4">-->
<!--              <template slot="title">选项4</template>-->
<!--              <el-menu-item index="2-4-1">选项1</el-menu-item>-->
<!--            </el-submenu>-->
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-user"></i>
              <span>个人中心</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="3-1" @click="AdminLogOut">退出登录</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
<!--          <el-menu-item index="4">-->
<!--            <i class="el-icon-setting"></i>-->
<!--            <span slot="title">导航四</span>-->
<!--          </el-menu-item>-->
        </el-row>
      </el-menu>
    </el-col>
      <router-view></router-view>
    </el-row>
  </div>
</template>

<script>
import Vue from 'vue'
import axios from 'axios'
import router from '../../router'

export default {
  name: 'AdminIndex',
  methods: {
    handleOpen: function (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose: function (key, keyPath) {
      console.log(key, keyPath)
    },
    ToComplaints () {
      return this.$router.push({
        path: '/Complaints',
        name: 'Complaints'
      })
    },
    ToDebates () {
      router.push(({path: '/Debates'}))
    },
    ToReports () {
      router.push(({path: '/Reports'}))
    },
    ExportUser () {
      axios.get(`admin/exportUser`, {}).then(res => {
        if (res.data.status === 100) {
          alert('导出成功')
        } else {
          alert('导出失败')
        }
      }).catch(err => {
        alert(err)
        router.replace('/login')
      })
    },
    ExportLog () {
      axios.get(`admin/exportLog`, {}).then(res => {
        if (res.data.status === 100) {
          alert('导出成功')
        } else {
          alert('导出失败')
        }
      }).catch(err => {
        alert(err)
        router.replace('/login')
      })
    },
    AdminLogOut () {
      axios.get(`admin/logout`, {}).then(res => {
        if (res.data.status === 100) {
          alert('退出成功')
          return this.$router.push({
            path: '/login'
          })
        } else {
          alert('操作失败')
        }
      }).catch(err => {
        alert(err)
      })
    }
  }
}
var Main = {
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  }
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
</script>

<style scoped>

</style>
